package com.test.jdk8;

import com.model.Hero;

import java.util.*;
import java.util.stream.Collectors;

/**
 * Created by Miracle Luna on 2020/5/17
 */
public class ThreeCountryLambda {
    public static void main(String[] args) {
        List<Hero> heroList =  new ArrayList<>();
        Map<String, List<Hero>> heroListMap = new HashMap<String, List<Hero>>();

        Hero liubei = new Hero("刘备", "蜀国");
        Hero zhugeliang = new Hero("诸葛亮", "蜀国");

        Hero sunce = new Hero("孙策", "吴国");
        Hero zhouyu = new Hero("周瑜", "吴国");

        Hero caocao = new Hero("曹操", "魏国");
        Hero guojia = new Hero("郭嘉", "魏国");

        heroList.add(liubei);
        heroList.add(zhugeliang);

        heroList.add(sunce);
        heroList.add(zhouyu);

        heroList.add(caocao);
        heroList.add(guojia);

        // 按照所属国家分组
        heroListMap = heroList.stream().collect(Collectors.groupingBy(hero -> hero.getCountry()));

     //   System.out.println(JSON.toJSONString(heroListMap));

    }
}